package com.example.smartcity.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.ViolationBean;

import java.util.List;

public class ViolationListAdapter extends ArrayAdapter<ViolationBean.RowsBean> {
    public int resource;
    public List<ViolationBean.RowsBean> list;
    public ViolationListAdapter(@NonNull Context context, int resource, @NonNull List<ViolationBean.RowsBean> list) {
        super(context, resource, list);
        this.resource = resource;
        this.list = list;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = null;
        ViewHolder holder = null;
        if (convertView==null){
            view = LayoutInflater.from(parent.getContext()).inflate(resource,parent,false);
            holder = new ViewHolder();
            holder.TVBadTime = view.findViewById(R.id.TV_badTime);
            holder.TVDeductMarks = view.findViewById(R.id.TV_deductMarks);
            holder.TVDisposeState = view.findViewById(R.id.TV_disposeState);
            holder.TVIllegalSites = view.findViewById(R.id.TV_illegalSites);
            holder.TVMoney = view.findViewById(R.id.TV_money);
            holder.TVLicencePlate = view.findViewById(R.id.TV_licencePlate);
            view.setTag(holder);
        }else{
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.TVMoney.setText(list.get(position).getMoney());
        holder.TVLicencePlate.setText(list.get(position).getLicencePlate());
        holder.TVIllegalSites.setText(list.get(position).getIllegalSites());
        holder.TVDisposeState.setText(list.get(position).getDisposeState().equals("1")?"已处理":"未处理");
        holder.TVBadTime.setText(list.get(position).getBadTime());
        holder.TVDeductMarks.setText(list.get(position).getDeductMarks());
        return view;
    }
    static class ViewHolder{
        private TextView TVBadTime;
        private TextView TVMoney;
        private TextView TVIllegalSites;
        private TextView TVLicencePlate;
        private TextView TVDisposeState;
        private TextView TVDeductMarks;
    }
}
